﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using V5_DBUtility;
using V5_Model;

namespace V5_DAL.SqlServer
{
    public class DALGZUser
    {
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Bc_Custom");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ModelGZUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Bc_Custom(");
            strSql.Append("ID,CustomNo,CustomName,CustomShortName,CustomShortCutName,CustomTypeID,RecommendedID,CustomSaleType,Address,POINT,Discount,PostalCode,MobilePhone,TelePhone,FaxNo,Sex,Email,Website,TaxNo,BankNo,Bank,LinkMan,AccountReceivable,FirstAccountReceivable,CardNo,ExistingIntegral,ConsumptionIntegral,ResidualIntegral,CreditMoney,IsUseCredit,CreditDay,CreditStartDate,CreditEndDate,Birthday,CreateDate,AdvanceLastMoney,Pwd,IsSMS,SellerID,Disable,Remark)");
            strSql.Append(" values (");
            strSql.Append("@ID,@CustomNo,@CustomName,@CustomShortName,@CustomShortCutName,@CustomTypeID,@RecommendedID,@CustomSaleType,@Address,@POINT,@Discount,@PostalCode,@MobilePhone,@TelePhone,@FaxNo,@Sex,@Email,@Website,@TaxNo,@BankNo,@Bank,@LinkMan,@AccountReceivable,@FirstAccountReceivable,@CardNo,@ExistingIntegral,@ConsumptionIntegral,@ResidualIntegral,@CreditMoney,@IsUseCredit,@CreditDay,@CreditStartDate,@CreditEndDate,@Birthday,@CreateDate,@AdvanceLastMoney,@Pwd,@IsSMS,@SellerID,@Disable,@Remark)");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@CustomNo", SqlDbType.VarChar,200),
					new SqlParameter("@CustomName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomShortName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomShortCutName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomTypeID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@RecommendedID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@CustomSaleType", SqlDbType.Int,4),
					new SqlParameter("@Address", SqlDbType.VarChar,200),
					new SqlParameter("@POINT", SqlDbType.Decimal,9),
					new SqlParameter("@Discount", SqlDbType.Decimal,9),
					new SqlParameter("@PostalCode", SqlDbType.VarChar,100),
					new SqlParameter("@MobilePhone", SqlDbType.VarChar,100),
					new SqlParameter("@TelePhone", SqlDbType.VarChar,100),
					new SqlParameter("@FaxNo", SqlDbType.VarChar,100),
					new SqlParameter("@Sex", SqlDbType.VarChar,100),
					new SqlParameter("@Email", SqlDbType.VarChar,100),
					new SqlParameter("@Website", SqlDbType.VarChar,200),
					new SqlParameter("@TaxNo", SqlDbType.VarChar,100),
					new SqlParameter("@BankNo", SqlDbType.VarChar,100),
					new SqlParameter("@Bank", SqlDbType.VarChar,100),
					new SqlParameter("@LinkMan", SqlDbType.VarChar,100),
					new SqlParameter("@AccountReceivable", SqlDbType.Decimal,13),
					new SqlParameter("@FirstAccountReceivable", SqlDbType.Decimal,13),
					new SqlParameter("@CardNo", SqlDbType.VarChar,100),
					new SqlParameter("@ExistingIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@ConsumptionIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@ResidualIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@CreditMoney", SqlDbType.Decimal,9),
					new SqlParameter("@IsUseCredit", SqlDbType.Bit,1),
					new SqlParameter("@CreditDay", SqlDbType.Int,4),
					new SqlParameter("@CreditStartDate", SqlDbType.DateTime),
					new SqlParameter("@CreditEndDate", SqlDbType.DateTime),
					new SqlParameter("@Birthday", SqlDbType.DateTime),
					new SqlParameter("@CreateDate", SqlDbType.DateTime),
					new SqlParameter("@AdvanceLastMoney", SqlDbType.Decimal,9),
					new SqlParameter("@Pwd", SqlDbType.VarChar,100),
					new SqlParameter("@IsSMS", SqlDbType.Bit,1),
					new SqlParameter("@SellerID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@Disable", SqlDbType.Bit,1),
					new SqlParameter("@Remark", SqlDbType.VarChar,4000)};
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = model.CustomNo;
            parameters[2].Value = model.CustomName;
            parameters[3].Value = model.CustomShortName;
            parameters[4].Value = model.CustomShortCutName;
            parameters[5].Value = model.CustomTypeID;
            parameters[6].Value = Guid.NewGuid();
            parameters[7].Value = model.CustomSaleType;
            parameters[8].Value = model.Address;
            parameters[9].Value = model.POINT;
            parameters[10].Value = model.Discount;
            parameters[11].Value = model.PostalCode;
            parameters[12].Value = model.MobilePhone;
            parameters[13].Value = model.TelePhone;
            parameters[14].Value = model.FaxNo;
            parameters[15].Value = model.Sex;
            parameters[16].Value = model.Email;
            parameters[17].Value = model.Website;
            parameters[18].Value = model.TaxNo;
            parameters[19].Value = model.BankNo;
            parameters[20].Value = model.Bank;
            parameters[21].Value = model.LinkMan;
            parameters[22].Value = model.AccountReceivable;
            parameters[23].Value = model.FirstAccountReceivable;
            parameters[24].Value = model.CardNo;
            parameters[25].Value = model.ExistingIntegral;
            parameters[26].Value = model.ConsumptionIntegral;
            parameters[27].Value = model.ResidualIntegral;
            parameters[28].Value = model.CreditMoney;
            parameters[29].Value = model.IsUseCredit;
            parameters[30].Value = model.CreditDay;
            parameters[31].Value = model.CreditStartDate;
            parameters[32].Value = model.CreditEndDate;
            parameters[33].Value = model.Birthday;
            parameters[34].Value = model.CreateDate;
            parameters[35].Value = model.AdvanceLastMoney;
            parameters[36].Value = model.Pwd;
            parameters[37].Value = model.IsSMS;
            parameters[38].Value = Guid.NewGuid();
            parameters[39].Value = model.Disable;
            parameters[40].Value = model.Remark;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelGZUser model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Bc_Custom set ");
            strSql.Append("CustomName=@CustomName,");
            strSql.Append("CustomShortName=@CustomShortName,");
            strSql.Append("CustomShortCutName=@CustomShortCutName,");
            strSql.Append("CustomTypeID=@CustomTypeID,");
            strSql.Append("RecommendedID=@RecommendedID,");
            strSql.Append("CustomSaleType=@CustomSaleType,");
            strSql.Append("Address=@Address,");
            strSql.Append("POINT=@POINT,");
            strSql.Append("Discount=@Discount,");
            strSql.Append("PostalCode=@PostalCode,");
            strSql.Append("MobilePhone=@MobilePhone,");
            strSql.Append("TelePhone=@TelePhone,");
            strSql.Append("FaxNo=@FaxNo,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("Email=@Email,");
            strSql.Append("Website=@Website,");
            strSql.Append("TaxNo=@TaxNo,");
            strSql.Append("BankNo=@BankNo,");
            strSql.Append("Bank=@Bank,");
            strSql.Append("LinkMan=@LinkMan,");
            strSql.Append("AccountReceivable=@AccountReceivable,");
            strSql.Append("FirstAccountReceivable=@FirstAccountReceivable,");
            strSql.Append("CardNo=@CardNo,");
            strSql.Append("ExistingIntegral=@ExistingIntegral,");
            strSql.Append("ConsumptionIntegral=@ConsumptionIntegral,");
            strSql.Append("ResidualIntegral=@ResidualIntegral,");
            strSql.Append("CreditMoney=@CreditMoney,");
            strSql.Append("IsUseCredit=@IsUseCredit,");
            strSql.Append("CreditDay=@CreditDay,");
            strSql.Append("CreditStartDate=@CreditStartDate,");
            strSql.Append("CreditEndDate=@CreditEndDate,");
            strSql.Append("Birthday=@Birthday,");
            strSql.Append("CreateDate=@CreateDate,");
            strSql.Append("AdvanceLastMoney=@AdvanceLastMoney,");
            strSql.Append("Pwd=@Pwd,");
            strSql.Append("IsSMS=@IsSMS,");
            strSql.Append("SellerID=@SellerID,");
            strSql.Append("Disable=@Disable,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where ID=@ID and CustomNo=@CustomNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@CustomName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomShortName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomShortCutName", SqlDbType.VarChar,200),
					new SqlParameter("@CustomTypeID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@RecommendedID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@CustomSaleType", SqlDbType.Int,4),
					new SqlParameter("@Address", SqlDbType.VarChar,200),
					new SqlParameter("@POINT", SqlDbType.Decimal,9),
					new SqlParameter("@Discount", SqlDbType.Decimal,9),
					new SqlParameter("@PostalCode", SqlDbType.VarChar,100),
					new SqlParameter("@MobilePhone", SqlDbType.VarChar,100),
					new SqlParameter("@TelePhone", SqlDbType.VarChar,100),
					new SqlParameter("@FaxNo", SqlDbType.VarChar,100),
					new SqlParameter("@Sex", SqlDbType.VarChar,100),
					new SqlParameter("@Email", SqlDbType.VarChar,100),
					new SqlParameter("@Website", SqlDbType.VarChar,200),
					new SqlParameter("@TaxNo", SqlDbType.VarChar,100),
					new SqlParameter("@BankNo", SqlDbType.VarChar,100),
					new SqlParameter("@Bank", SqlDbType.VarChar,100),
					new SqlParameter("@LinkMan", SqlDbType.VarChar,100),
					new SqlParameter("@AccountReceivable", SqlDbType.Decimal,13),
					new SqlParameter("@FirstAccountReceivable", SqlDbType.Decimal,13),
					new SqlParameter("@CardNo", SqlDbType.VarChar,100),
					new SqlParameter("@ExistingIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@ConsumptionIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@ResidualIntegral", SqlDbType.Decimal,13),
					new SqlParameter("@CreditMoney", SqlDbType.Decimal,9),
					new SqlParameter("@IsUseCredit", SqlDbType.Bit,1),
					new SqlParameter("@CreditDay", SqlDbType.Int,4),
					new SqlParameter("@CreditStartDate", SqlDbType.DateTime),
					new SqlParameter("@CreditEndDate", SqlDbType.DateTime),
					new SqlParameter("@Birthday", SqlDbType.DateTime),
					new SqlParameter("@CreateDate", SqlDbType.DateTime),
					new SqlParameter("@AdvanceLastMoney", SqlDbType.Decimal,9),
					new SqlParameter("@Pwd", SqlDbType.VarChar,100),
					new SqlParameter("@IsSMS", SqlDbType.Bit,1),
					new SqlParameter("@SellerID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@Disable", SqlDbType.Bit,1),
					new SqlParameter("@Remark", SqlDbType.VarChar,4000),
					new SqlParameter("@ID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@CustomNo", SqlDbType.VarChar,200)};
            parameters[0].Value = model.CustomName;
            parameters[1].Value = model.CustomShortName;
            parameters[2].Value = model.CustomShortCutName;
            parameters[3].Value = model.CustomTypeID;
            parameters[4].Value = model.RecommendedID;
            parameters[5].Value = model.CustomSaleType;
            parameters[6].Value = model.Address;
            parameters[7].Value = model.POINT;
            parameters[8].Value = model.Discount;
            parameters[9].Value = model.PostalCode;
            parameters[10].Value = model.MobilePhone;
            parameters[11].Value = model.TelePhone;
            parameters[12].Value = model.FaxNo;
            parameters[13].Value = model.Sex;
            parameters[14].Value = model.Email;
            parameters[15].Value = model.Website;
            parameters[16].Value = model.TaxNo;
            parameters[17].Value = model.BankNo;
            parameters[18].Value = model.Bank;
            parameters[19].Value = model.LinkMan;
            parameters[20].Value = model.AccountReceivable;
            parameters[21].Value = model.FirstAccountReceivable;
            parameters[22].Value = model.CardNo;
            parameters[23].Value = model.ExistingIntegral;
            parameters[24].Value = model.ConsumptionIntegral;
            parameters[25].Value = model.ResidualIntegral;
            parameters[26].Value = model.CreditMoney;
            parameters[27].Value = model.IsUseCredit;
            parameters[28].Value = model.CreditDay;
            parameters[29].Value = model.CreditStartDate;
            parameters[30].Value = model.CreditEndDate;
            parameters[31].Value = model.Birthday;
            parameters[32].Value = model.CreateDate;
            parameters[33].Value = model.AdvanceLastMoney;
            parameters[34].Value = model.Pwd;
            parameters[35].Value = model.IsSMS;
            parameters[36].Value = model.SellerID;
            parameters[37].Value = model.Disable;
            parameters[38].Value = model.Remark;
            parameters[39].Value = model.ID;
            parameters[40].Value = model.CustomNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Bc_Custom ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelGZUser GetModel(Guid ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Bc_Custom ");
            strSql.Append(" where ID=@ID  ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.UniqueIdentifier,16)};
            parameters[0].Value = ID;

            ModelGZUser model = new ModelGZUser();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = new Guid(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomNo"] != null && ds.Tables[0].Rows[0]["CustomNo"].ToString() != "")
                {
                    model.CustomNo = ds.Tables[0].Rows[0]["CustomNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CustomName"] != null && ds.Tables[0].Rows[0]["CustomName"].ToString() != "")
                {
                    model.CustomName = ds.Tables[0].Rows[0]["CustomName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CustomShortName"] != null && ds.Tables[0].Rows[0]["CustomShortName"].ToString() != "")
                {
                    model.CustomShortName = ds.Tables[0].Rows[0]["CustomShortName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CustomShortCutName"] != null && ds.Tables[0].Rows[0]["CustomShortCutName"].ToString() != "")
                {
                    model.CustomShortCutName = ds.Tables[0].Rows[0]["CustomShortCutName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CustomTypeID"] != null && ds.Tables[0].Rows[0]["CustomTypeID"].ToString() != "")
                {
                    model.CustomTypeID = new Guid(ds.Tables[0].Rows[0]["CustomTypeID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RecommendedID"] != null && ds.Tables[0].Rows[0]["RecommendedID"].ToString() != "")
                {
                    model.RecommendedID = new Guid(ds.Tables[0].Rows[0]["RecommendedID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CustomSaleType"] != null && ds.Tables[0].Rows[0]["CustomSaleType"].ToString() != "")
                {
                    model.CustomSaleType = int.Parse(ds.Tables[0].Rows[0]["CustomSaleType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"].ToString() != "")
                {
                    model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["POINT"] != null && ds.Tables[0].Rows[0]["POINT"].ToString() != "")
                {
                    model.POINT = decimal.Parse(ds.Tables[0].Rows[0]["POINT"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Discount"] != null && ds.Tables[0].Rows[0]["Discount"].ToString() != "")
                {
                    model.Discount = decimal.Parse(ds.Tables[0].Rows[0]["Discount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PostalCode"] != null && ds.Tables[0].Rows[0]["PostalCode"].ToString() != "")
                {
                    model.PostalCode = ds.Tables[0].Rows[0]["PostalCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MobilePhone"] != null && ds.Tables[0].Rows[0]["MobilePhone"].ToString() != "")
                {
                    model.MobilePhone = ds.Tables[0].Rows[0]["MobilePhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TelePhone"] != null && ds.Tables[0].Rows[0]["TelePhone"].ToString() != "")
                {
                    model.TelePhone = ds.Tables[0].Rows[0]["TelePhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FaxNo"] != null && ds.Tables[0].Rows[0]["FaxNo"].ToString() != "")
                {
                    model.FaxNo = ds.Tables[0].Rows[0]["FaxNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Sex"] != null && ds.Tables[0].Rows[0]["Sex"].ToString() != "")
                {
                    model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "")
                {
                    model.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Website"] != null && ds.Tables[0].Rows[0]["Website"].ToString() != "")
                {
                    model.Website = ds.Tables[0].Rows[0]["Website"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TaxNo"] != null && ds.Tables[0].Rows[0]["TaxNo"].ToString() != "")
                {
                    model.TaxNo = ds.Tables[0].Rows[0]["TaxNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BankNo"] != null && ds.Tables[0].Rows[0]["BankNo"].ToString() != "")
                {
                    model.BankNo = ds.Tables[0].Rows[0]["BankNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Bank"] != null && ds.Tables[0].Rows[0]["Bank"].ToString() != "")
                {
                    model.Bank = ds.Tables[0].Rows[0]["Bank"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LinkMan"] != null && ds.Tables[0].Rows[0]["LinkMan"].ToString() != "")
                {
                    model.LinkMan = ds.Tables[0].Rows[0]["LinkMan"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AccountReceivable"] != null && ds.Tables[0].Rows[0]["AccountReceivable"].ToString() != "")
                {
                    model.AccountReceivable = decimal.Parse(ds.Tables[0].Rows[0]["AccountReceivable"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FirstAccountReceivable"] != null && ds.Tables[0].Rows[0]["FirstAccountReceivable"].ToString() != "")
                {
                    model.FirstAccountReceivable = decimal.Parse(ds.Tables[0].Rows[0]["FirstAccountReceivable"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CardNo"] != null && ds.Tables[0].Rows[0]["CardNo"].ToString() != "")
                {
                    model.CardNo = ds.Tables[0].Rows[0]["CardNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ExistingIntegral"] != null && ds.Tables[0].Rows[0]["ExistingIntegral"].ToString() != "")
                {
                    model.ExistingIntegral = decimal.Parse(ds.Tables[0].Rows[0]["ExistingIntegral"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ConsumptionIntegral"] != null && ds.Tables[0].Rows[0]["ConsumptionIntegral"].ToString() != "")
                {
                    model.ConsumptionIntegral = decimal.Parse(ds.Tables[0].Rows[0]["ConsumptionIntegral"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ResidualIntegral"] != null && ds.Tables[0].Rows[0]["ResidualIntegral"].ToString() != "")
                {
                    model.ResidualIntegral = decimal.Parse(ds.Tables[0].Rows[0]["ResidualIntegral"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreditMoney"] != null && ds.Tables[0].Rows[0]["CreditMoney"].ToString() != "")
                {
                    model.CreditMoney = decimal.Parse(ds.Tables[0].Rows[0]["CreditMoney"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsUseCredit"] != null && ds.Tables[0].Rows[0]["IsUseCredit"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsUseCredit"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsUseCredit"].ToString().ToLower() == "true"))
                    {
                        model.IsUseCredit = true;
                    }
                    else
                    {
                        model.IsUseCredit = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["CreditDay"] != null && ds.Tables[0].Rows[0]["CreditDay"].ToString() != "")
                {
                    model.CreditDay = int.Parse(ds.Tables[0].Rows[0]["CreditDay"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreditStartDate"] != null && ds.Tables[0].Rows[0]["CreditStartDate"].ToString() != "")
                {
                    model.CreditStartDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreditStartDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreditEndDate"] != null && ds.Tables[0].Rows[0]["CreditEndDate"].ToString() != "")
                {
                    model.CreditEndDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreditEndDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Birthday"] != null && ds.Tables[0].Rows[0]["Birthday"].ToString() != "")
                {
                    model.Birthday = DateTime.Parse(ds.Tables[0].Rows[0]["Birthday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateDate"] != null && ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AdvanceLastMoney"] != null && ds.Tables[0].Rows[0]["AdvanceLastMoney"].ToString() != "")
                {
                    model.AdvanceLastMoney = decimal.Parse(ds.Tables[0].Rows[0]["AdvanceLastMoney"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Pwd"] != null && ds.Tables[0].Rows[0]["Pwd"].ToString() != "")
                {
                    model.Pwd = ds.Tables[0].Rows[0]["Pwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsSMS"] != null && ds.Tables[0].Rows[0]["IsSMS"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsSMS"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsSMS"].ToString().ToLower() == "true"))
                    {
                        model.IsSMS = true;
                    }
                    else
                    {
                        model.IsSMS = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["SellerID"] != null && ds.Tables[0].Rows[0]["SellerID"].ToString() != "")
                {
                    model.SellerID = new Guid(ds.Tables[0].Rows[0]["SellerID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Disable"] != null && ds.Tables[0].Rows[0]["Disable"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Disable"].ToString() == "1") || (ds.Tables[0].Rows[0]["Disable"].ToString().ToLower() == "true"))
                    {
                        model.Disable = true;
                    }
                    else
                    {
                        model.Disable = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "")
                {
                    model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                }
                //if (ds.Tables[0].Rows[0]["TimeStamp"] != null && ds.Tables[0].Rows[0]["TimeStamp"].ToString() != "") {
                //    model.TimeStamp = DateTime.Parse(ds.Tables[0].Rows[0]["TimeStamp"].ToString());
                //}
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM Bc_Custom ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM Bc_Custom ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Bc_Custom ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        public int CheckUser(string UserName, string PassWord)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from Bc_Custom where CustomName ='{0}' and pwd='{1}'");

            object obj = DbHelperSQL.GetSingle(string.Format(strSql.ToString(), UserName, PassWord));
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        } 

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.CustomNo desc");
            }
            strSql.Append(")AS Row, T.*  from Bc_Custom T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Bc_Custom";
            parameters[1].Value = "CustomNo";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(string strFiled, int PageSize, int PageIndex, string strWhere, string strOrder, ref int RecordCount)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@OrderfldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@StatfldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
            parameters[0].Value = "Bc_Custom";
            parameters[1].Value = "*";
            parameters[2].Value = "ID";
            parameters[3].Value = "ID";
            parameters[4].Value = PageSize;
            parameters[5].Value = PageIndex;
            parameters[6].Value = 1;
            parameters[7].Value = 1;
            parameters[8].Value = strWhere;
            DataSet ds = DbHelperSQL.RunProcedure("UP_GetRecordByPageOrder", parameters, "ds");
            RecordCount = int.Parse("0" + ds.Tables[1].Rows[0][0].ToString());
            return ds;
        }

        #endregion  Method
    }
}